package com.cjh.admin.controller;

import com.alibaba.fastjson.JSON;
import com.cjh.common.dto.DeleteSpecificationsDTO;
import com.cjh.common.dto.SpecificationsDTO;
import com.cjh.common.dto.SpecificationsPagingDTO;
import com.cjh.common.response.Result;
import com.cjh.common.service.SpecificationsService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author caijiahuang
 * @since 2022-02-18 12:35:24
 */
@RestController
@RequestMapping("/specifications")
public class SpecificationsController {
    @Autowired
    SpecificationsService specificationsService;

    @ApiOperation("获取分页规格")
    @GetMapping("/getPagingSpecifications")
    public Result getPagingSpecifications(@RequestParam String specificationsPagingDTO){
        return specificationsService.getPagingSpecifications(JSON.parseObject(specificationsPagingDTO, SpecificationsPagingDTO.class));
    }

    @ApiOperation("获取所有规格")
    @GetMapping("/getAllSpecifications")
    public Result getAllSpecifications(){
        return specificationsService.getAllSpecifications();
    }

    @RequiresPermissions(value = {"addRule"})
    @ApiOperation("增加规格")
    @PostMapping("/addSpecifications")
    public Result addSpecifications(@RequestBody SpecificationsDTO specificationsDTO){
        return specificationsService.addSpecifications(specificationsDTO);
    }
    @RequiresPermissions(value = {"deleteRule"})
    @ApiOperation("删除一条规格")
    @PostMapping("/deleteSpecifications")
    public Result deleteSpecifications(@RequestBody DeleteSpecificationsDTO deleteSpecificationsDTO){
        return specificationsService.deleteSpecifications(deleteSpecificationsDTO);
    }
    @RequiresPermissions(value = {"deleteRule"})
    @ApiOperation("删除多条规格")
    @PostMapping("/deleteManySpecifications")
    public Result deleteManySpecifications(@RequestBody List<DeleteSpecificationsDTO> deleteSpecificationsDTOList){
        return specificationsService.deleteManySpecifications(deleteSpecificationsDTOList);
    }
    @RequiresPermissions(value = {"updateRule"})
    @ApiOperation("修改规格")
    @PostMapping("/updateSpecifications")
    public Result updateSpecifications(@RequestBody SpecificationsDTO specificationsDTO){
        return specificationsService.updateSpecifications(specificationsDTO);
    }
}
